/**
 * Created by Lenovo on 2016/11/16.
 */
//待修改完善。。。
    function addItem(){
        var t1=document.getElementById("t1");
        var todoForm=document.getElementById("todoForm");
        t1.style.display="none";
        todoForm.style.display="block";

    };

    function confirmClick(){
        var todoItem=document.getElementById("todoItem");
        var todoThing=document.getElementById("todoThing");
        var todoTime=document.getElementById("todoTime");
        var todoLeader=document.getElementById("todoLeader");
        var newLi=document.createElement("li");
        newLi.className="nLi";
        var newItem=document.createTextNode("待办项："+todoThing.value
        +",  时间段："+todoTime.value+",    负责人："+todoLeader.value);

        var todoDelay=document.createElement("a");
        var node = document.createTextNode("  ▽");
        todoDelay.appendChild(node);
        todoDelay.setAttribute("href","#");
        todoDelay.className="toDelay";


        var todoNot=document.createElement("a");
        node = document.createTextNode("  x");
        todoNot.appendChild(node);
        todoNot.setAttribute("href","#");
        todoNot.className="toNot";

        var todoYes=document.createElement("a");
        node = document.createTextNode("  √");
        todoYes.appendChild(node);
        todoYes.setAttribute("href","#");
        todoYes.className="toYes";

        newLi.appendChild(newItem);
        newLi.appendChild(todoDelay);
        newLi.appendChild(todoNot);
        newLi.appendChild(todoYes);
        todoItem.appendChild(newLi);

        document.getElementById("todoForm").style.display="none";
        document.getElementById("t1").style.display="block";

        todoThing.value=" ";
        todoTime.value=" ";
        todoLeader.value=" ";

      //阻止默认行为
//位置。。。？
        var i=0;
        var cancelItem=document.getElementById("cancelItem");
        var finishedItem=document.getElementById("finishedItem");
        var delayItem=document.getElementById("delayItem");



        //紧急item的 × 触发事件
        var sNot= document.getElementsByClassName("toNot");
        var sNotLength=sNot.length;
        for(i=0;i<sNotLength;i++){
            sNot[i].onclick=toCancel;
        }
        function toCancel() {
            var node=this.parentNode.cloneNode(true);
            node.childNodes[2].setAttribute("class","toDelete");//!!
            node.removeChild(node.lastChild);
            node.removeChild(node.childNodes[1]);
            cancelItem.appendChild(node);
            this.parentNode.remove();
        };


//紧急item的 √ 触发事件
        var sYes= document.getElementsByClassName("toYes");
        var sYesLength=sYes.length;
        for(i=0;i<sYesLength;i++){
            sYes[i].onclick=toFinish;
        }
         function  toFinish() {
             var node=this.parentNode.cloneNode(true);
             node.childNodes[2].setAttribute("class","toDelete");//!!
             node.removeChild(node.lastChild);
             node.removeChild(node.childNodes[1]);
             finishedItem.appendChild(node);
             this.parentNode.remove();
         }


//紧急item的 ▽ 触发事件
        var sDelay= document.getElementsByClassName("toDelay");
        var sDelayLength=sYes.length;
        for(i=0;i<sDelayLength;i++){
            sDelay[i].onclick=toDelay;
        }
        function  toDelay() {
            var node=this.parentNode.cloneNode(true);
            node.childNodes[2].setAttribute("class","toDelete");//!!
            node.removeChild(node.lastChild);
            delayItem.appendChild(node);
            this.parentNode.remove();
        }


        //修改节点className失败？？
       //完成item的 × 触发事件/移除项目触发事件(有bug)
        var sDelete= document.getElementsByClassName("toDelete");
        var sDeleteLength=sDelete.length;
//获取当前点击的节点！
//为动态生成的节点绑定动态事件！
        for(i=0;i<sDeleteLength;i++){
            sDelete[i].onclick=toDelete;
        }
        function toDelete() {
            this.parentNode.remove();
        };



    };



function cancelClick(){
    var t1=document.getElementById("t1");
    var todoForm=document.getElementById("todoForm");
    t1.style.display="block";
    todoForm.style.display="none";
}



          /*  cancelItem.appendChild(this.parentNode);

        this.parent().appendTo(cancelItem);
        this.parent().find(".toDelay").remove();
        this.parent().find(".toYes").remove();*/


    /*$todoItem.on('click','.toYes',function(e){

        $(this).parent().appendTo($finishedItem);
        $(this).parent().find(".toDelay").remove();
        $(this).remove();
    });
    $todoItem.on('click','.toDelay',function(e){

        $(this).parent().appendTo($delayItem);
        $(this).html("△");
        $(this).parent().find(".toYes").hide();

    });
    $finishedItem.on('click','.toNot',function(e){
        $(this).parent().remove();
    });

    $delayItem.on('click','.toNot',function(e){
        $(this).parent().appendTo($cancelItem);
        $(this).parent().find(".toDelay").remove();
        $(this).parent().find(".toYes").remove();
    });
    $delayItem.on('click','.toDelay',function(e){
        $(this).parent().appendTo($todoItem);
        $(this).html("▽");
        $(this).parent().find(".toYes").show();
    });
    $cancelItem.on('click','.toNot',function(e){
        $(this).parent().remove();
    });*/


